import threading
import time

# 参数定义最多几个线程同时使用资源
semaphore = threading.Semaphore(3)

def func(j):
    if semaphore.acquire():
        # for i in range(5):
        print(f"j:{j}")
        # print(threading.currentThread().getName()+'get semaphore')
        print('-------------')

        time.sleep(15)
        semaphore.release()
        # print(threading.currentThread().getName()+'release semaphore')

if __name__ == '__main__':

    for j in range(8):
        t1 = threading.Thread(target=func,args=(j,))
        t1.start()